//
//  ServiceSearchViewController.m
//  Utils
//
//  Created by enghou on 2018/6/7.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "ServiceSearchViewController.h"
#import "ServiceObjectChooseViewController.h"
#import "MemberItemModel.h"
#import "ObjectsItemModel.h"
@interface ServiceSearchViewController ()<TotalProtocol>

@property (weak, nonatomic) IBOutlet UITextField *serviceAddressField;

@property (weak, nonatomic) IBOutlet UITextField *serviceOfferField;

@property (weak, nonatomic) IBOutlet UITextField *otherOfferField;

@property (weak, nonatomic) IBOutlet UITextField *serviceObjectField;

@property (weak, nonatomic) IBOutlet UITextField *beginDateField;

@property (weak, nonatomic) IBOutlet UITextField *endDateField;


@property(nonatomic,strong)UIDatePicker *datePicker;
@end

@implementation ServiceSearchViewController{
    NSString *serviceOfferId;
    NSString *serviceObjectId;
}

-(instancetype)init{
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"Service" bundle:[NSBundle mainBundle]];
    return [story instantiateViewControllerWithIdentifier:@"ServiceSearchViewController"];
}

- (IBAction)submitAction:(id)sender {
    
}

- (IBAction)beginAction:(id)sender {
    [self.beginDateField becomeFirstResponder];
}

- (IBAction)endAction:(id)sender {
    [self.endDateField becomeFirstResponder];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0, self.view.width, 240)];
    self.datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];
    self.datePicker.backgroundColor = [UIColor whiteColor];
    self.datePicker.datePickerMode = UIDatePickerModeDate;
    self.datePicker.date = [NSDate date];
    self.beginDateField.inputView = self.datePicker;
    self.beginDateField.inputAccessoryView = [self inputAccessView];
    
    self.endDateField.inputView = self.datePicker;
    self.endDateField.inputAccessoryView = [self inputAccessView];
}

#pragma mark - UITableViewDelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    ServiceObjectChooseViewController *vc = [segue destinationViewController];
    vc.theDelegate = self;
}

#pragma TotalProtocol
-(void)fetchModel:(id)model{
    if ([model isKindOfClass:[ObjectsItemModel class]]) {
        ObjectsItemModel *item = (ObjectsItemModel *)model;
        self.serviceObjectField.text = item.memberName;
        serviceObjectId = item.memberBaseId;
    }else if ([model isKindOfClass:[MemberItemModel class]]) {
        MemberItemModel *item = (MemberItemModel *)model;
        self.serviceOfferField.text = item.memberName;
        serviceOfferId = item.memberBaseId;
    }else if ([model isKindOfClass:[ObjectsItemModel class]]){
        ObjectsItemModel *item = (ObjectsItemModel *)model;
        self.serviceObjectField.text = item.memberName;
        serviceObjectId = item.memberBaseId;
    }
}

@end
